import axios from "axios"
import { getToken, removeToken, removeUser } from "@/utils/auth"
import router from "@/router"
const baseURL = window.location.host.indexOf("localhost") > -1 ? "http://" + location.host : "https://zhsy.hqzhw.cn/"
const instance = axios.create({
    baseURL
})

instance.interceptors.request.use((config) => {
    config.headers['token'] = getToken()
    return config
}, (error) => {

})

instance.interceptors.response.use((res) => {
    const code = res.data.code || 0
    if (code == 402 || code == 403) {
        ElMessage.error(res.data.msg)
        removeToken()
        removeUser()
        router.push('/login')
    }
    return res.data
})


export default instance


